<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      /* li:nth-child(even) {
        background-color: aqua;
      }
      li:nth-child(odd) {
        background-color: pink;
      } */
    </style>
  </head>
  <body>
    <ul>
      <li>迪丽热巴</li>
      <li>迪丽热巴</li>
      <li>迪丽热巴</li>
      <li>迪丽热巴</li>
      <li>迪丽热巴</li>
    </ul>
    <script>
      var lis = document.querySelectorAll("li");
      for (var i = 0; i < lis.length; i++) {
        if (i % 2 === 0) {
          lis[i].style.backgroundColor = "#ccc";
        } else {
          lis[i].style.backgroundColor = "pink";
        }
        // lis[i].style.backgroundColor = i % 2 === 0 ? "#ccc" : "pink";
      }
      console.log(list);
    </script>
  </body>
</html>
